<?php
/**
 * @brief recovery_hp protocol
 *
 * @param post uid User ID
 * @return True/False (True : money, hp)
 * @author con100 <con100@playplus.net>
 * @since 05/04/2013
 * @copyright Copyright (c) 2013, PlayPlus
 **/

include 'dbconn.php';
include 'config.php';

$user_id = mysql_real_escape_string($_POST['uid']);

$sql = "select nation, hp, timestemp_hp, max_hp, money from ebs_member where id='$user_id'";
$res = mysql_query($sql);
$data = mysql_fetch_assoc($res);
//hp 보정
$time_hp = (int)($data['hp']+(time()-$data['timestemp_hp']) * $hp_sec);

if($data['hp'] > 0){
	$data['hp'] = min($time_hp, $data['max_hp']);
}else if($time_hp > $data['max_hp']){
	$data['hp'] = $data['max_hp'];
}
//회복비용
$pay_recovery_hp = _getRecoveryPay_($data);
//체력회복
if($data['hp'] < $data['max_hp'] && $pay_recovery_hp <= $data['money']){
	$data['hp'] = $data['max_hp'];
	$data['money'] -= $pay_recovery_hp;
	$sql = "update ebs_member set hp='$data[hp]', money='$data[money]' where id='$user_id'";
	$res = mysql_query($sql);
	$result = array("Result"=>TRUE, "money"=>$money, "hp"=>$data['hp']);
}
else{
	$result = array("Result"=>FALSE);
}
echo json_encode($result);
/*
header('Content-type: text/xml; charset=UTF-8');

$writer = new XMLWriter();
$writer->openMemory();
$writer->setIndent(true);
$writer->setIndentString('  ');
$writer->startDocument('1.0', 'UTF-8');

$writer->startElement('recovery_hp');
	$writer->startElement('result');
	$writer->text($result);
	$writer->endElement();
	if($result == "TRUE"){
		$writer->startElement('money');
		$writer->text($money);
		$writer->endElement();
	}
$writer->endElement();

echo($writer->outputMemory());

//국비 조회
$no_nation = $data['nation'];
if($no_nation != 0){
	$sql = "select money from ebs_nation where no='$no_nation'";
	$res = mysql_query($sql);
	$nation = mysql_fetch_array($res);
}
//국비에 쌓임
if($no_nation != 0){
	$nation['money'] += $pay_recovery_hp;
	$sql = "update ebs_nation set money='$nation[money]' where no='$no_nation'";
	$res = mysql_query($sql);
}
*/
?>